package com.xuyiwei.xblog.business.system.service.impl;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.xuyiwei.xblog.business.system.dao.NoticeMapper;
import com.xuyiwei.xblog.business.system.model.Notice;
import com.xuyiwei.xblog.business.system.result.notice.out.NoticeDto;
import com.xuyiwei.xblog.business.system.service.INoticeService;
import com.xuyiwei.xblog.core.base.constant.enums.CommonStatusEnum;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 * 通知表 服务实现类
 * </p>
 *
 * @author stylefeng123
 * @since 2018-02-22
 */
@Service
public class NoticeServiceImpl extends ServiceImpl<NoticeMapper, Notice> implements INoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    @Override
    public List<Notice> list(String condition) {
        return this.baseMapper.list(condition);
    }

    @Override
    @Transactional
    public void deleteNoticesByIds(List<Long> ids) {
        List<Notice> list = this.selectBatchIds(ids);
        for(Notice n:list){
            n.setStatus(CommonStatusEnum.DELETE.getKey());
            n.updateById();
        }
    }

    @Override
    public void deleteAllNotice() {
        noticeMapper.deleteAllNotice();
    }

    @Override
    public List<NoticeDto> findPageByCondition(Page<NoticeDto> page, @Param("vo") String condition, String orderByField, boolean isAsc) {
        List<NoticeDto> list =  noticeMapper.findPageByCondition(page,condition,orderByField,isAsc);
        return list;
    }
}
